package com.pktechan.api.service.impl;

import com.pktechan.api.base.BaseMapper;
import com.pktechan.api.base.BaseServiceImpl;
import com.pktechan.api.dao.WxPayRefundOrderMapper;
import com.pktechan.api.entity.WxPayRefundOrder;
import com.pktechan.api.service.WxPayRefundOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service("wxPayRefundOrderService")
@Transactional
public class WxPayRefundOrderServiceImpl extends BaseServiceImpl<WxPayRefundOrder> implements WxPayRefundOrderService {

    @Autowired
    private WxPayRefundOrderMapper wxPayRefundOrderMapper;

    /**
     * 由业务类实现
     *
     * @return
     */
    @Override
    public BaseMapper<WxPayRefundOrder> getBaseMapper() {
        return wxPayRefundOrderMapper;
    }

    /**
     * 添加退款订单
     *
     * @param paraMap
     */
    @Override
    public void addWxPayRefundOrder(Map<String, String> paraMap) {
        WxPayRefundOrder wxPayRefundOrder = new WxPayRefundOrder();
        wxPayRefundOrder.setAppId(paraMap.get("appid"));
        wxPayRefundOrder.setMchId(paraMap.get("mch_id"));
        wxPayRefundOrder.setOutRefundNo(paraMap.get("out_refund_no"));
        wxPayRefundOrder.setRefundId(paraMap.get("refund_id"));
        wxPayRefundOrder.setOutTradeNo(paraMap.get("out_trade_no"));
        wxPayRefundOrder.setTransactionId(paraMap.get("transaction_id"));
        wxPayRefundOrder.setTotalFee(Integer.parseInt(paraMap.get("total_fee")));
        wxPayRefundOrder.setRefundFee(Integer.parseInt(paraMap.get("refund_fee")));
        wxPayRefundOrder.setCashFee(Integer.parseInt(paraMap.get("cash_fee")));
        wxPayRefundOrder.setCashRefundFee(Integer.parseInt(paraMap.get("cash_refund_fee")));
        wxPayRefundOrder.setRefundState(paraMap.get("result_code"));
        wxPayRefundOrder.setErrCode(paraMap.get("err_code"));
        wxPayRefundOrder.setErrCodeDes(paraMap.get("err_code_des"));
        wxPayRefundOrderMapper.save(wxPayRefundOrder);
    }
}
